<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="handler">修改对象数据</button>
        <ul>
          <li v-for="value,key in person" :key="item">{{key}}--{{value}}</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false;
        
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    person:{
                        name:"laowu",
                        age:18,
                        score:{
                            math:100,
                            ch:90,
                        }
                    },
                    
                };
            },
            methods: {
                handler(){
                    // 1.可以精准获取属性，没有限制(响应式)
                    // this.person.score.ch=120;
                    // 2.修改的方式是赋值的(响应式)解构赋值
                    // this.person={...this.person,age:22}
                    // 3.直接新增不是响应式的，初始化就给data
                    // this.person.sex = "男";
                    // 4.vm.$set 和Vue.set方法可以添加(响应式)
                    // this.$set(this.person, "sex", "男");
                    // Vue.set(this.person, "sex", "男");
                    //5.直接删除删除一个属性(是没有响应式的)
                    // delete this.person.age;
                    //6.删除并且具有响应式,使用Vue.delete或vm.$delete方法
                    // this.$delete(this.person, "age");
                    // Vue.delete(this.person, "age");
                    //7.重新赋值做操作(基本都有响应式,但是略微麻烦,并且代码不直观)
                    delete this.person.age;
                    this.person = { ...this.person };
                }
            },
        })
</script>
</body>

</html>